package com.apes.fn.server.workOrder.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.contract.model.Contract;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.ServeType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;


/**
 * Creator: zouyc
 * CreateDate: 2020-11-30 17:58
 * Description:
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = MaintenanceOrderReport.CONST_TABLE_NAME)
public class MaintenanceOrderReport extends Model {
    public static final String CONST_TABLE_NAME = "ser_maintenance_order_report";

    //各类单据编码
    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "施工编码", padding = 12)
    private String id;

    @Column(name = "service_plan_i_Id", length = 64)
    @Comment("方案明细编码")
    private String servicePlanItemId;

    @Column(name = "service_plan_Id", length = 64)
    @Comment("方案编码")
    private String servicePlanId;

    //单据类型
    @Column(name = "business_type", length = 32)
    @Comment("单据类型")
    private String businessType ;

    @Column(name = "business_type_name", length = 64)
    @Comment("单据类型名称")
    private String businessTypeName = "服务工单";

    @Column(name = "plan_source_type", length = 64)
    @Comment("方案来源类型")
    private String planSourceTypeName ;

    @Column(name = "plan_source_from", length = 64)
    @Comment("方案来源单号")
    private String planSourceFrom ;

    @Column(name = "source_type", length = 64)
    @Comment("来源类型")
    private String sourceType ;

    @Column(name = "source_from", length = 64)
    @Comment("来源单号")
    private String sourceFrom ;

    @Column(name = "state", length = 32)
    @Comment("工单状态")
    private String state;

    @Column(name = "work_state", length = 32)
    @Comment("工单明细状态")
    private String workState;

    @Column(name = "dispatche_state", length = 32)
    @Comment("派工状态")
    private String dispatcheState;

    @Column(name = "lock_state", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("锁住状态")
    private boolean lockState;

    @Comment("外协类型")
    @States(name = "外协类型", values = {
            @State(id = "notOut", name = "非外协"),
            @State(id = "inPlatform", name = "平台内"),
            @State(id = "outPlatform", name = "平台外")
    })
    @Column(name = "out_assist_type", nullable = false, columnDefinition = "varchar2(16) default 'notOut'")
    private String outAssistType;

    @States(name = "确定外协类型", values = {
            @State(id = "false", name = "平台外"),
            @State(id = "true", name = "平台内")
    })
    @Column(name = "out_assist_type_confirm", nullable = false, columnDefinition = "number(1,0) default 1")
    private boolean outAssistTypeConfirm = true;

    //-----------------车辆信息 ，会员信息
    @Column(name = "fn_customer_e_id", length = 255)
    @Comment("赋能客户车辆扩展信息编码")
    private String fnCustomerExpandId;

    @Column(name = "CAR_LICENSE", length = 255)
    @Comment("车牌")
    private String carLicense;

    @Column(name = "MOBILE", length = 255)
    @Comment("手机")
    private String mobile;

    @Column(name = "REALNAME", length = 255)
    @Comment("用户名")
    private String REALNAME;

    //---商品信息
    @Column(name = "product_id",  length = 64)
    @Comment("商品")
    private String productId;

    @Column(name = "product_name",  length = 64)
    @Comment("商品")
    private String productName;

    @Column(name = "uom_id",  length = 64)
    @Comment("计量单位编码")
    private Long uom;

    @Column(name = "uom_name",  length = 64)
    @Comment("计量单位编码")
    private String uomName;

    @Column(name = "sale_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("销售数量")
    private double saleQty = 0;

    @Column(name = "product_rule", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("带安标记")
    private boolean productRule;

    @Column(name = "serve_type_id",  length = 64)
    @Comment("服务类型")
    private String serveTypeId;

    @Column(name = "serve_type_name",  length = 64)
    @Comment("服务类型")
    private String serveTypeName;

    @Column(name = "STANDERHOUR", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("标准时长")
    private int STANDERHOUR = 0;

    //----其他
    @Column(name ="out_assist_remark", columnDefinition = "CLOB")
    @Comment("平台外协助原因")
    private String outAssistRemark;

    @Column(name = "contract_id",  length = 64)
    @Comment("采购合同")
    private String contract;

    @Column(name = "contract_Name",  length = 64)
    @Comment("采购合同")
    private String contractName;

    @Column(name = "platform_id",  length = 64)
    @Comment("平台")
    private String platform;

    @Column(name = "platform_name",  length = 64)
    @Comment("平台")
    private String platformName;

    @Column(name = "work_platform", length = 32)
    @States(name = "施工端", values = {
            @State(id = "cosmetology", name = "美容"),
            @State(id = "machineRepa", name = "机修"),
            @State(id = "sprayPaint", name = "钣喷"),
            @State(id = "other", name = "不施工")
    })
    private String workPlatform;

    @Column(name ="point", length = 32)
    @Comment("当前节点")
    @States(name = "施工端", values = {
            @State(id = "start", name = "开始类"),
            @State(id = "pause", name = "暂停类"),
            @State(id = "end", name = "完结类")
    })
    private String point;


    //门店信息 公司信息
    @Column(name = "belong_dept_id", length = 64)
    @Comment("所属门店")
    private String belongDeptId;

    @Column(name = "belong_dept_name", length = 255)
    @Comment("所属门店")
    private String belongDeptName;

    @Column(name = "inner_dept_id",  length = 64)
    @Comment("内协门店")
    private String innerDeptId;

    @Column(name = "inner_dept_name",  length = 64)
    @Comment("内协门店")
    private String innerDeptName;

    @Column(name = "company_id",  length = 64)
    @Comment("公司")
    private String company;  //单据所属公司

    @Column(name = "company_name",  length = 64)
    @Comment("公司")
    private String companyName;  //单据所属公司

    //人员信息
    @Column(name = "creator_uName",  length = 64)
    @Comment("创建人人")
    private String creatorName;

    @Column(name = "termination_uid",  length = 64)
    @Comment("终止人")
    private String terminationUid;

    @Column(name = "termination_uName",  length = 64)
    @Comment("终止人")
    private String terminationUName;

    @Column(name = "finish_uid",  length = 64)
    @Comment("完成人")
    private String finishUid;

    @Column(name = "finish_uName",  length = 64)
    @Comment("完成人")
    private String finishUName;

    @Column(name = "to_inner_uid",  length = 64)
    @Comment("转内协人")
    private String toInnerUid;

    @Column(name = "to_inner_uName",  length = 64)
    @Comment("转内协人")
    private String toInnerUName;

    @Column(name = "dispatch_uid",  length = 64)
    @Comment("派工人")
    private String dispatchUid;

    @Column(name = "dispatch_uName",  length = 64)
    @Comment("派工人")
    private String dispatchUName;

    @Column(name = "dispatch_back_uid",  length = 64)
    @Comment("派工退回人")
    private String dispatchBackUid;

    @Column(name = "dispatch_back_uName",  length = 64)
    @Comment("派工退回人")
    private String dispatchBackUName;

    @Column(name = "out_back_uid",  length = 64)
    @Comment("外协退回人")
    private String outBackUid;

    @Column(name = "out_back_uName",  length = 64)
    @Comment("外协退回人")
    private String outBackUName;

    @Column(name = "to_out_uid",  length = 64)
    @Comment("转外协人")
    private String toOutUid;

    @Column(name = "to_out_uName",  length = 64)
    @Comment("转外协人")
    private String toOutUName;

    @Column(name ="worker1", columnDefinition = "CLOB")
    @Comment("工序施工人1")
    private String worker1;

    @Column(name ="worker2", columnDefinition = "CLOB")
    @Comment("工序施工人2")
    private String worker2;

    @Column(name ="worker3", columnDefinition = "CLOB")
    @Comment("工序施工人3")
    private String worker3;

    @Column(name ="worker4", columnDefinition = "CLOB")
    @Comment("工序施工人4")
    private String worker4;

    @Column(name ="worker1_show", columnDefinition = "CLOB")
    @Comment("工序施工人1")
    private String worker1Show;

    @Column(name ="worker2_show", columnDefinition = "CLOB")
    @Comment("工序施工人2")
    private String worker2Show;

    @Column(name ="worker3_show", columnDefinition = "CLOB")
    @Comment("工序施工人3")
    private String worker3Show;

    @Column(name ="worker4_show", columnDefinition = "CLOB")
    @Comment("工序施工人4")
    private String worker4Show;


    //时间信息
    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "termination_date")
    @Comment("终止日期")
    private Date terminationDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "finish_date")
    @Comment("完成日期")
    private Date finishDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "work_start_time")
    @Comment("施工开始时间")
    private Date workStartTime;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "to_inner_date")
    @Comment("转内协日期")
    private Date toInnerDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dispatch_date")
    @Comment("派工日期")
    private Date dispatchDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "out_back_date")
    @Comment("外协退回日期")
    private Date outBackDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dispatch_back_date")
    @Comment("派工退回日期")
    private Date dispatchBackDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "to_out_date")
    @Comment("转外协日期")
    private Date toOutDate;

    @Column(name = "worked_time", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("已工作时长")
    private double workedTime = 0;

    @Column(name = "pauseed_time", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("已暂停时长")
    private double pauseedTime = 0;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "WORKSTART")
    @Comment("开始时间")
    private Date WORKSTART;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "WORKEND")
    @Comment("结束时间")
    private Date WORKEND;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "point_start_time")
    @Comment("节点开始时间")
    private Date pointStartTime;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "reach_date")
    @Comment("供应商到店日期")
    private Date reachDate;

    //价格信息
    @Column(name = "platform_price_cost_in_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("平台成本单价")
    private double platformPriceCosInTax = 0;   // 供应商对平台的价格

    @Column(name = "price_cost_unit_in_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("含税成本单价")
    private double priceCostUnitInTax = 0;      // 平台对赋能店的的价格

    @Column(name = "platform_tax_temp", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("平台成本单价(外协)")
    private double platformPriceCosInTaxTemp = 0;

    @Column(name = "price_tax_temp", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("含税成本单价(外协)")
    private double priceCostUnitInTaxTemp = 0;
}